package org.ax.controller.plan;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.ax.data.Result;
import org.ax.pojo.plan.Custom;
import org.ax.pojo.plan.Product;
import org.ax.service.plan.CustomService;
import org.ax.service.plan.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 编程人:赵浩鑫
 * 时间:2021-02-25-16:42
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @RequestMapping("/find")
    public ModelAndView find(){
        return new ModelAndView("plan/product");
    }
    @Autowired
    ProductService productService;
    @Autowired
    Result result;
    @GetMapping("/list")
    public Result search(String productName, String status, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "6") int limit){
        Page<Product> productList = productService.findProductList(new Page(page, limit), productName, status);
        result.setData(productList.getRecords());
        result.setCount(productList.getTotal());
        return result;
    }
    @PostMapping("/addProduct")
    public Result addProduct(Product product){
        result.setMsg(productService.addProduct(product)?"添加成功":"添加失败");
        return result;

    }
    @PostMapping("/updateProduct")
    public Result updateProduct(Product product){
        result.setMsg(productService.updProduct(product)?"修改成功":"修改失败");
        return result;

    }
    @GetMapping("/patchDel")
    public Result patchDel(String[] productId){
        result.setMsg(productService.deletesProduct(productId)?"批量删除成功":"批量删除失败");
        return result;
    }
    @GetMapping("/productList")
    public Result selectList(){
        result.setData(productService.availableProduct());
        return result;
    }
}
